Structure and Interpretation of Computer Programs by Harold Abelson

Structure and Interpretation of Computer Programs by Harold Abelson

Author:Harold Abelson [Abelson, Harold]
Language: eng
Format: epub, pdf
Tags: Computers, Computer Science, Programming Languages, General, Lisp, Software Development & Engineering
ISBN: 9780262011532
Google: 1DrQngEACAAJ
Publisher: MIT Press
Published: 1996-07-15T00:32:40.957012+00:00


(define x (stream-map show (stream-enumerate-interval 0 10)))

(stream-ref x 5)

(stream-ref x 7)

Exercise 3.52. Consider the sequence of expressions

(define sum 0)

(define (accum x)

(set! sum (+ x sum))

sum)

(define seq (stream-map accum (stream-enumerate-interval 1 20)))

(define y (stream-filter even? seq))

(define z (stream-filter (lambda (x) (= (remainder x 5) 0))

seq))

(stream-ref y 7)

(display-stream z)

What is the value of sum after each of the above expressions is evaluated? What is the printed response to evaluating the stream-ref and display-stream expressions? Would these responses differ if we had implemented (delay <exp>) simply as (lambda () <exp>) without using the optimization provided by memo-proc ? Explain.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.